using Common.Communal;
using MediatR;
using Product.API.Read.Applications.Commands.Bom;
using SqlSugar;

namespace Product.API.Read.Applications.CommandHandlers.Bom
{
    /// <summary>
    /// 产品全量查询命令处理
    /// </summary>
    public class ProductAllQueryCommandHandler : IRequestHandler<ProductAllQueryCommand, ApiResult<List<ERP.Domain.Products.Product>>>
    {
        /// <summary>
        /// SqlSugar
        /// </summary>
        private readonly ISqlSugarClient db;

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="db">SqlSugar</param>
        public ProductAllQueryCommandHandler(ISqlSugarClient db)
        {
            this.db = db;
        }

        /// <summary>
        /// 处理
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>返回任务</returns>
        public Task<ApiResult<List<ERP.Domain.Products.Product>>> Handle(ProductAllQueryCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<ERP.Domain.Products.Product>> result = new ApiResult<List<ERP.Domain.Products.Product>>();
            result.Code = EnumCode.Ok;
            result.Message = EnumCode.Ok.ToString();

            var data = db.Queryable<ERP.Domain.Products.Product>()
                         .Where(x => x.IsDelete == false)
                         .ToList();
            result.Data = data;

            return Task.FromResult(result);
        }
    }
}


